package com.lxmes.gs.controller;

import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import com.lxmes.gs.domain.issuedProjectsVO.*;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.gs.domain.IssuedProjects;
import com.lxmes.gs.service.IIssuedProjectsService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 项目下发Controller
 * 
 * @author wdf
 * @date 2023-04-24
 */
@Api(tags = "项目下发")    
@RestController
@RequestMapping("/gs/issuedProjects")
public class IssuedProjectsController extends BaseController{
    @Autowired
    private IIssuedProjectsService issuedProjectsService;

    /**
     * 查询项目下发列表
     */
    @ApiOperation("查询项目下发列表")
    @PreAuthorize("@ss.hasPermi('gs:issuedProjects:list')")
    @GetMapping("/list")
    public TableDataInfo list(IssuedProjectsSearchVO issuedProjects){
        startPage();
        List<IssuedProjects> list = issuedProjectsService.selectIssuedProjectsList(BeanUtil.copyProperties(issuedProjects,IssuedProjects.class));
        return getDataTable(Convert.convert(new TypeReference<List<IssuedProjectsResultVO>>() {},list));
}

    /**
     * 导出项目下发列表
     */
    @ApiOperation("导出项目下发列表")
    @PreAuthorize("@ss.hasPermi('gs:issuedProjects:export')")
    @Log(title = "项目下发", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IssuedProjects issuedProjects){
        List<IssuedProjects> list = issuedProjectsService.selectIssuedProjectsList(issuedProjects);
        List<IssuedProjectsExportVO> exportList = Convert.convert(new TypeReference<List<IssuedProjectsExportVO>>() {}, list);
        ExcelUtil<IssuedProjectsExportVO> util = new ExcelUtil<IssuedProjectsExportVO>(IssuedProjectsExportVO.class);
        util.exportExcel(response, exportList, "项目下发数据");
    }

    /**
     * 获取项目下发详细信息
     */
    @ApiOperation("获取项目下发详细信息")
    @PreAuthorize("@ss.hasPermi('gs:issuedProjects:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(issuedProjectsService.selectIssuedProjectsById(id));
    }

    /**
     * 新增项目下发
     */
    @ApiOperation("新增项目下发")
    @PreAuthorize("@ss.hasPermi('gs:issuedProjects:add')")
    @Log(title = "项目下发", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IssuedProjectsCreateVO issuedProjects){
        return toAjax(issuedProjectsService.insertIssuedProjects(BeanUtil.copyProperties(issuedProjects,IssuedProjects.class)));
    }

    /**
     * 修改项目下发
     */
    @ApiOperation("修改项目下发")
    @PreAuthorize("@ss.hasPermi('gs:issuedProjects:edit')")
    @Log(title = "项目下发", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IssuedProjectsUpdateVO issuedProjects){
        return toAjax(issuedProjectsService.updateIssuedProjects(BeanUtil.copyProperties(issuedProjects,IssuedProjects.class)));
    }

    /**
     * 删除项目下发
     */
    @ApiOperation("删除项目下发")
    @PreAuthorize("@ss.hasPermi('gs:issuedProjects:remove')")
    @Log(title = "项目下发", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(issuedProjectsService.deleteIssuedProjectsByIds(ids));
    }
    /**
     * 审核项目下发
     */
    @ApiOperation("审核项目下发")
    @PreAuthorize("@ss.hasAnyPermi('gs:issuedProjects:audit')")
    @Log(title = "审核项目下发")
	@PostMapping("/auditIssuedProjects/{ids}")
    public AjaxResult auditIssuedProjects(@PathVariable Long[] ids){
        return toAjax(issuedProjectsService.auditIssuedProjects(ids));
    }
    /**
     * 导入项目下发
     */
    @Log(title = "项目下发", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception{
        ExcelUtil<IssuedProjectsImportVO> util = new ExcelUtil<>(IssuedProjectsImportVO.class);
        List<IssuedProjectsImportVO> issuedProjectsList = util.importExcel(file.getInputStream());
        String message = issuedProjectsService.imporIteminfo(Convert.convert(new TypeReference<List<IssuedProjects>>() {},issuedProjectsList), updateSupport);
        return AjaxResult.success(message);
    }
    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException{
        ExcelUtil<IssuedProjectsImportVO> util = new ExcelUtil<>(IssuedProjectsImportVO.class);
        util.importTemplateExcel(response,"项目下发");
    }
}
